define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'knscy.orders/index',
        add_url: 'knscy.orders/add',
        edit_url: 'knscy.orders/edit',
        show_log_url: 'knscy.orders/logs',
        delete_url: 'knscy.orders/delete',
        export_url: 'knscy.orders/export',
        modify_url: 'knscy.orders/modify',
    };

    var Controller = {

        index: function () {

            ea.table.render({
                init: init,
                toolbar:['refresh' ,'delete','export'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id', search: false},
                    {field: 'order_no', title: '订单号',minWidth:180},
                    // {field: 'openid', title: '用户openid'},
                    // {field: 'uniacid', title: '公众号ID'},
                    {field: 'user_id', title: '用户ID',minWidth:100},
                    // {field: 'order_status', title: '订单状态',minWidth:100},
                    {field: 'status_label', title: '订单状态',minWidth:100,search:'select' ,selectList: $nodes.statusLabel },
                    {field: 'order_money', title: '订单金额',minWidth:100, search: false},
                    {field: 'pay_money', title: '支付金额',minWidth:100, search: false},
                    {field: 'discount_money', title: '折扣金额',minWidth:100, search: false},
                    {field: 'pay_status', search: 'select', selectList: ["未支付","待支付",'支付中','已支付'], title: '支付状态',minWidth:120},
                    {field: 'pay_type',search: 'select', selectList: ["-","微信支付"],  title: '支付方式',minWidth:100, search: false},
                    {field: 'good_title', title: '商品',minWidth:150},
                    {field: 'good_id', title: '商品ID',minWidth:100},
                    {field: 'ticket_id', title: '门票ID',minWidth:100},
                    {field: 'remark', title: '下单人备注', templet: ea.table.text,minWidth:120},
                    {field: 'can_refund', search: 'select', selectList: ["否","是"], title: '可退',minWidth:120, search: false},
                    {field: 'need_check', search: 'select', selectList: ["否","是"], title: '需换票',minWidth:120, search: false},
                    // {field: 'sort', title: '排序', edit: 'text',minWidth:80, search: false},
                    // {field: 'status', search: 'select', selectList: ["禁用","启用"], title: '状态', templet: ea.table.switch,minWidth:130},
                    {field: 'create_time', title: '创建时间',minWidth:150, search: "range"},
                    {fixed:"right",width: 180, title: '操作', templet: ea.table.tool, operat:[
                            'edit|明细',
                            [{
                                class: 'layui-btn  layui-btn-xs',
                                method: 'open',
                                field: 'id',
                                icon: '',
                                text:  '日志',
                                title: '订单日志',
                                auth: 'edit',
                                url:  init.show_log_url,
                            }]
                        ]},
                ]],
            });

            ea.listen();
        },
        logs: function () {
            ea.table.render({
                init: init,
                url: ea.url(init.show_log_url),
                toolbar: ['refresh' ,'export'],
                search:false,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'id' ,align: 'left'},
                    {field: 'order_no', title: '订单NO',minWidth:180, align:'left'},
                    {field: 'content', title: '日志内容',minWidth:400, align:'left'},
                    {field: 'create_time',minWidth:200, title: '创建时间',search:"range", align:'left'},
                    {field: 'tag', title: '日志标识',minWidth:260, align:'left'},
                    // {fixed:"right",width: 150, title: '操作', templet: ea.table.tool},
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});